!pr2
Converting to Motorola S-Format............Bob Sander-Cederlof

Last April I told how to convert object code to the Intellec Hex Format (AAL pages 14-18, April, 1984).  Both Intel and Zilog use that format.  Motorola, on the other hand, has its own format for object code.  It is similar, but it is significantly different.  If you are programming for a Motorola chip, or using a PROM burner that uses Motorola format, then the following program is for you.

The Motorola S-Type format has three kinds of records:  header, data, and end-of-file.  Each record begins with the letter "S" and ends with a carriage return linefeed (CRLF).  According to the samples I have seen, all of the bytes in a record are in ASCII code with the high bit zero.  (Apple peripherals tend to like the high bit = 1, so I made this an option.)  The maximum length including the "S" and up to but not including the CRLF is 64 "frames".  Between the "S" and CRLF, each record consists of five fields:

!lm+5
Record format field:  ASCII 0, 1, or 9 (hex $30, $31, or $39) for header, data, or end-of-file records respectively.

Byte count field:  the count expressed as two ASCII digits of the number of bytes (half the number of frames) from address field through the checksum field.  The minimum is 3, and the maximum is 60 decimal or $3C hexadecimal.

Address field:  four frames representing the four digits of the load address for data bytes in a data record, or the run address in an end-of-file record.  All four digits will be "0" in a header record.

Data field:  two hex digits for each byte of data.  The number of bytes will be 3 less than the number specified in the byte count field, because that count includes two bytes for the address and one byte for the checksum.

Checksum field:  two hex digits representing the 1's complement of the binary sum of all the bytes in the previous four fields.
!lm-5

If you compare the S-Type format with the Intellec format, you will note several differences:

!lm+5
*  records start with "S" instead of ":"
*  the fields are in a different order
*  there was no header record for Intellec
*  the byte count covers three fields instead of only
   the data field
*  the checksum is computed by a different algorithm
   and covers different data.
!lm-5

I tried to use as much as possible of the Intellec program when writing the Motorola program.  You will find a lot of similarities if you compare the two.  Both are designed to be used with the monitor's control-Y instruction.  Both expect you to enter the output slot number or address in zero-page bytes 0 and 1.

The Motorola program requires two additional pieces of information.  It needs a byte at 0002 which will be either $00 or $80, denoting whether to set the high bit to 0 or 1 on every output byte.  It also needs an eight character name for the header record.  This should be entered in zero-page locations 0003 through 000A.

For example, assume the object code I want to format is in the Apple between $6000 and $67FF.  In the target processor it will load at address $1000.  The name of the program is "SAMPLE".  I want to send the data with the high bit = 0.  The device I want to send it to is connected to an intelligent peripheral card in slot 2.  Here is what I type:

!lm+2
]BRUN B.MOTOROLA FORMATTER     (or :BRUN B.MOTOROLA FORMATTER
]CALL -151                     (or :MNTR)
*0:2 0                         (send to slot 2)
*:0                            (hi-bit = 0)
*:53 41 4D 50 4C 45 20 20      ("SAMPLE")
*1000<6000.67FF^Y              (^Y means control-Y)
!lm-2

I recommend comparing this program and my description of it with the Intellec program and article in the April AAL.  Here is the Motorola formatter:
